import { components } from '@/types/api';
import request from '@/utils/request';

/**
 * 登录
 */
export const signin = async (
    data: components['schemas']['ParamsUserSignin']
) => {
    const response = await request.post<
        components['schemas']['Response_SchemaUserTokens_']
    >(`/api/v1/user/authorize/signin`, data);
    return response.data;
};
/**
 * 注册
 */
export const signup = async (
    data: components['schemas']['ParamsUserSignup']
) => {
    const response = await request.post<
        components['schemas']['Response_SchemaUserTokens_']
    >(`/api/v1/user/authorize/signup`, data);
    return response.data;
};
/**
 * 获取用户信息
 */
export const getUserProfile = async () => {
    const response = await request.get<
        components['schemas']['Response_SchemaUserOpen_']
    >(`/api/v1/user/profile`);
    return response.data;
};
/**
 * 获取分类
 */
export const getCategory = async (categoryId: number) => {
    const response = await request.get<
        components['schemas']['Response_List_SchemaCategoryChilds__']
    >(`/api/v1/product/category/${categoryId}`);
    return response.data;
};
/**
 * 获取分类搜索
 */
export const getCategorySearch = async (
    data: components['schemas']['ParamsCategorySearch']
) => {
    const response = await request.post<
        components['schemas']['Response_List_SchemaCategoryChilds__']
    >(`/api/v1/product/category/search`, data);
    return response.data;
};
/**
 * 获取分类属性
 */
export const getCategoryAttributes = async (categoryId: number) => {
    const response = await request.get<
        components['schemas']['Response_List_SchemaCategoryAttributes__']
    >(`/api/v1/product/category/${categoryId}/attributes`);
    return response.data;
};
/**
 * 获取品牌搜索
 */
export const getBrandSearch = async (
    data: components['schemas']['ParamsBrandSearch']
) => {
    const response = await request.post<
        components['schemas']['Response_list_SchemaBrandSearch__']
    >(`/api/v1/product/brands/search`, data);
    return response.data;
};
/**
 * 获取商品材料搜索
 */
export const getProductMaterialsSearch = async (
    data: components['schemas']['ParamsMaterialsSearch']
) => {
    const response = await request.post<
        components['schemas']['Response_SchemaMaterialsSearch_'][]
    >(`/api/v1/product/materials/search`, data);
    return response.data;
};
/**
 * 获取商品材料目标
 */
export const getProductMaterialsTarget = async (
    data: components['schemas']['ParamsMaterialsTarget']
) => {
    const response = await request.put<
        components['schemas']['Response_SchemaStatus_']
    >(`/api/v1/product/materials/target`, data);
    return response.data;
};
/**
 * 获取商品材料删除
 */
export const getProductMaterialsDelete = async (
    data: components['schemas']['ParamsMaterialsDelete']
) => {
    const response = await request.delete<
        components['schemas']['Response_SchemaStatus_']
    >(`/api/v1/product/materials`, { data });
    return response.data;
};
/**
 * 获取商品材料更新
 */
export const getProductMaterialsUpdate = async (
    material_id: number,
    data: components['schemas']['ParamsMaterialsUpdate']
) => {
    const response = await request.put<
        components['schemas']['Response_SchemaStatus_']
    >(`/api/v1/product/materials/${material_id}`, data);
    return response.data;
};
/**
 * 获取商品材料文件夹搜索
 */
export const getProductMaterialsFolderSearch = async (
    data: components['schemas']['ParamsMaterialsFolderSearch']
) => {
    const response = await request.post<
        components['schemas']['Response_List_SchemaMaterialsFolderSearch__']
    >(`/api/v1/product/materials/folder/search`, data);
    return response.data;
};
/**
 * 获取商品材料文件夹创建
 */
export const getProductMaterialsFolderCreate = async (
    data: components['schemas']['ParamsMaterialsFolderCreate']
) => {
    const response = await request.post<
        components['schemas']['Response_SchemaMaterialsFolderSearch_']
    >(`/api/v1/product/materials/folder/create`, data);
    return response.data;
};
/**
 * 获取商品材料文件夹更新
 */
export const getProductMaterialsFolderUpdate = async (
    folderId: number,
    data: components['schemas']['ParamsMaterialsFolderUpdate']
) => {
    const response = await request.put<
        components['schemas']['Response_SchemaMaterialsFolderSearch_']
    >(`/api/v1/product/materials/folder/${folderId}`, data);
    return response.data;
};
/**
 * 获取商品材料文件夹删除
 */
export const getProductMaterialsFolderDelete = async (folderId: number) => {
    const response = await request.delete<
        components['schemas']['Response_SchemaStatus_']
    >(`/api/v1/product/materials/folder/${folderId}`);
    return response.data;
};
/**
 * 获取商品尺码表创建
 */
export const getProductSizeChartCreate = async (
    data: components['schemas']['ParamsSizeChartCreate']
) => {
    const response = await request.post<
        components['schemas']['Response_SchemaSizeChart_']
    >(`/api/v1/product/sizechart`, data);
    return response.data;
};
/**
 * 获取商品尺码表更新
 */
export const getProductSizeChartUpdate = async (
    sizechart_id: number,
    data: components['schemas']['ParamsSizeChartCreate']
) => {
    const response = await request.put<
        components['schemas']['Response_SchemaSizeChart_']
    >(`/api/v1/product/sizechart/${sizechart_id}`, data);
    return response.data;
};
/**
 * 获取商品尺码表搜索
 */
export const getProductSizeChartSearch = async (
    data: components['schemas']['ParamsSizeChartSearch']
) => {
    const response = await request.post<
        components['schemas']['Response_SchemaSizeChart_']
    >(`/api/v1/product/sizechart/search`, data);
    return response.data;
};
/**
 * 商品发布
 */
export const getProductCreate = async (
    data: components['schemas']['ParamsProductPublish']
) => {
    const response = await request.post<
        components['schemas']['Response_SchemaStatus_']
    >(`/api/v1/product/create`, data);
    return response.data;
};
/**
 * 商品草稿
 */
export const getProductDraftCreate = async (
    data: components['schemas']['ParamsProductCreate']
) => {
    const response = await request.post<
        components['schemas']['Response_SchemaProductCreate_']
    >(`/api/v1/product/draft/create`, data);
    return response.data;
};
/**
 * 商品草稿详情
 */
export const getProductDraftDetail = async (product_id: number) => {
    const response = await request.get<
        components['schemas']['Response_SchemaProductCreate_']
    >(`/api/v1/product/draft/${product_id}`);
    return response.data;
};
/**
 * 商品搜索
 */
export const getProductSearch = async (
    data: components['schemas']['ParamsProductSearch']
) => {
    const response = await request.post<
        components['schemas']['Response_list_SchemaProductSearch__']
    >(`/api/v1/product/search`, data);
    return response.data;
};
/**
 * 获取创作者选品中心商品列表
 */
export const getProductsForCreator = async (data: {
    keyword: string | null;
    category_id: number | null;
    sort: string;
    pagination: {
        page: number;
        size: number;
    };
}) => {
    console.log('API函数接收的参数:', JSON.stringify(data));

    // 确保category_id是number类型或null
    const params = {
        ...data,
        category_id:
            data.category_id !== null ? Number(data.category_id) : null,
    };

    console.log('发送到服务器的实际参数:', JSON.stringify(params));

    const response = await request.post<
        components['schemas']['Response_list_SchemaProductSearch__']
    >(`/api/v1/product/products`, params);
    return response.data;
};
/**
 * 获取卖家店铺检查
 */
export const getSellerShopCheck = async () => {
    const response = await request.get<
        components['schemas']['SchemaSellerShopCheck']
    >(`/api/v1/seller/shop/check`);
    return response.data;
};
/**
 * 获取卖家店铺详情
 */
export const getSellerShopDetail = async () => {
    const response = await request.get<
        components['schemas']['Response_SchemaSellerShopDetail_']
    >(`/api/v1/seller/shop`);
    return response.data;
};
/**
 * 获取卖家店铺申请创建
 */
export const getSellerApplicationCreateStart = async (
    data: components['schemas']['ParamsSellerApplicationCreateStart']
) => {
    const response = await request.post<
        components['schemas']['Response_SchemaSellerApplicationDetail_']
    >(`/api/v1/seller/application/start`, data);
    return response.data;
};
/**
 * 获取卖家店铺申请创建验证
 */
export const getSellerApplicationCreateVerification = async (
    data: components['schemas']['ParamsSellerApplicationCreateVerification']
) => {
    const response = await request.post<
        components['schemas']['Response_SchemaSellerApplicationDetail_']
    >(`/api/v1/seller/application/verification`, data);
    return response.data;
};
/**
 * 获取卖家店铺申请创建基础
 */
export const getSellerApplicationCreateBasic = async (
    data: components['schemas']['ParamsSellerApplicationCreateBasic']
) => {
    const response = await request.post<
        components['schemas']['Response_SchemaSellerApplicationDetail_']
    >(`/api/v1/seller/application/basic`, data);
    return response.data;
};
/**
 * 获取卖家店铺申请详情
 */
export const getSellerApplicationDetail = async () => {
    const response = await request.get<
        components['schemas']['Response_SchemaSellerApplicationDetail_']
    >(`/api/v1/seller/application`);
    return response.data;
};
/**
 * 获取卖家店铺上传
 */
export const getSellerUpload = async (data: any) => {
    const response = await request.post<
        components['schemas']['Response_SchemaImage_']
    >(`/api/v1/seller/upload`, data, {
        headers: {
            'Content-Type': 'multipart/form-data',
        },
    });
    return response.data;
};
/**
 * 获取商品图片上传
 */
export const getProductImagesUpload = async (data: any) => {
    const response = await request.post<
        components['schemas']['Response_SchemaMaterialsSearch_']
    >(`/api/v1/product/images/upload`, data, {
        headers: {
            'Content-Type': 'multipart/form-data',
        },
    });
    return response.data;
};
/**
 * 获取商品文件上传
 */
export const getProductFilesUpload = async (data: any) => {
    const response = await request.post<
        components['schemas']['Response_SchemaMaterialsSearch_']
    >(`/api/v1/product/files/upload`, data, {
        headers: {
            'Content-Type': 'multipart/form-data',
        },
    });
    return response.data;
};
/**
 * 获取卖家制造商创建
 */
export const getSellerManufacturerCreate = async (
    data: components['schemas']['ParamsManufacturerCreate']
) => {
    const response = await request.post<
        components['schemas']['Response_SchemaManufacturer_']
    >(`/api/v1/seller/manufacturer`, data);
    return response.data;
};
/**
 * 获取卖家制造商更新
 */
export const getSellerManufacturerUpdate = async (
    manufacturer_id: number,
    data: components['schemas']['ParamsManufacturerCreate']
) => {
    const response = await request.put<
        components['schemas']['Response_SchemaManufacturer_']
    >(`/api/v1/seller/manufacturer/${manufacturer_id}`, data);
    return response.data;
};
/**
 * 获取卖家制造商搜索
 */
export const getSellerManufacturerSearch = async (
    data: components['schemas']['ParamsManufacturerSearch']
) => {
    const response = await request.post<
        components['schemas']['Response_SchemaManufacturer_']
    >(`/api/v1/seller/manufacturer/search`, data);
    return response.data;
};
/**
 * 获取卖家责任人创建
 */
export const getSellerResponsibleCreate = async (
    data: components['schemas']['ParamsResponsibleCreate']
) => {
    const response = await request.post<
        components['schemas']['Response_SchemaResponsible_']
    >(`/api/v1/seller/responsible`, data);
    return response.data;
};
/**
 * 获取卖家责任人更新
 */
export const getSellerResponsibleUpdate = async (
    responsible_id: number,
    data: components['schemas']['ParamsResponsibleCreate']
) => {
    const response = await request.put<
        components['schemas']['Response_SchemaResponsible_']
    >(`/api/v1/seller/responsible/${responsible_id}`, data);
    return response.data;
};
/**
 * 获取卖家责任人搜索
 */
export const getSellerResponsibleSearch = async (
    data: components['schemas']['ParamsResponsibleSearch']
) => {
    const response = await request.post<
        components['schemas']['Response_SchemaResponsible_']
    >(`/api/v1/seller/responsible/search`, data);
    return response.data;
};
/**
 * 获取物流区搜索
 */
export const getLogisticsDistrictSearch = async (
    data: components['schemas']['ParamsLogisticsDistrictSearch']
) => {
    const response = await request.post<
        components['schemas']['Response_list_SchemaLogisticsDistrictSearch__']
    >(`/api/v1/logistics/district/search`, data);
    return response.data;
};

/**
 * 获取第三方同步
 */
export const getThirdPartySyncTiktok = async (product_id: string) => {
    const response = await request.get<
        components['schemas']['Response_SchemaProductCreate_']
    >(`/api/v1/product/syncing/${product_id}/tiktok`);
    return response.data;
};

/**
 * 上传图片
 */
export const getUploadImage = async (data: any) => {
    const response = await request.post<any>(`/api/v1/base/oss/temp`, data, {
        headers: {
            'Content-Type': 'multipart/form-data',
        },
    });
    return response.data;
};

/**
 * 图生图
 */
export const getImage2Image = async (data: any) => {
    const response = await request.post<any>(`/api/v1/pic/image2image`, data);
    return response.data;
};

/**
 * 生成图片结果查询
 */
export const getPicResult = async (data: any) => {
    const response = await request.post<any>(`/api/v1/pic/result`, data);
    return response.data;
};

/**
 * 多图生成视频
 */
export const getMultiImageVideo = async (data: any) => {
    const response = await request.post<any>(
        `/api/v1/video/multi-image2video`,
        data
    );
    return response.data;
};

/**
 * 单图特效视频
 */
export const getOneImageEffectsVideo = async (data: any) => {
    const response = await request.post<any>(
        `/api/v1/video/effects/one-image2video`,
        data
    );
    return response.data;
};

/**
 * 多图特效视频
 */
export const getMultiImageEffectsVideo = async (data: any) => {
    const response = await request.post<any>(
        `/api/v1/video/effects/multi-image2video`,
        data
    );
    return response.data;
};

/**
 * 多图视频结果查询
 */
export const getVideoResult = async (data: any) => {
    const response = await request.post<any>(`/api/v1/video/result`, data);
    return response.data;
};

/**
 * 特效视频结果查询
 */
export const getEffectsVideoResult = async (data: any) => {
    const response = await request.post<any>(
        `/api/v1/video/effects/result`,
        data
    );
    return response.data;
};

/**
 * 粉丝互动视频列表查询
 */
export const getVideoList = async (data: any) => {
    const response = await request.post<any>(`/api/v1/video/list`, data);
    return response.data;
};

/**
 * 用户注册
 */
export const getAccountSign = async (data: any) => {
    const response = await request.post<any>(`/api/v1/account/sign`, data);
    return response.data;
};

/**
 * 用户登录
 */
export const getAccountLogin = async (data: any) => {
    const response = await request.post<any>(`/api/v1/account/login`, data);
    return response.data;
};

/**
 * 用户登出
 */
export const getAccountLogout = async (data: any) => {
    const response = await request.post<any>(`/api/v1/account/logout`, data);
    return response.data;
};

/**
 * 用户忘记密码
 */
export const getAccountForget = async (data: any) => {
    const response = await request.post<any>(`/api/v1/account/forget`, data);
    return response.data;
};

/**
 * 用户修改密码
 */
export const getAccountPsd = async (data: any) => {
    const response = await request.post<any>(`/api/v1/account/psd`, data);
    return response.data;
};

/**
 * 站点商品列表查询
 */
export const getProductList = async (data: any) => {
    const response = await request.post<any>(`/api/v1/product/list`, data);
    return response.data;
};

/**
 * 站点商品详情查询
 */
export const getProductDetail = async (data: any) => {
    const response = await request.post<any>(`/api/v1/product/detail`, data);
    return response.data;
};
